package com.example;

/**
 * Created by dllo on 16/1/20.
 */
public abstract class Duck {
    private FlyBehavior flyBehavior;
    private QuackBehavior quackBehavior;
    public abstract void display();

    public abstract void swim();

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }



    public void performFly() {
        if (flyBehavior != null) {
            flyBehavior.fly();
        }else {
            System.out.print("没有这个方法");
        }
    }

    public void performQuack() {
        if (quackBehavior != null) {
            quackBehavior.quack();
        }else {
            System.out.print("没有这个方法");
        }
    }


}
